/*
 * Copyright 2012-2022 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.boot.web.context;

import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.web.server.WebServerFactory;

/**
 * 当在{@link WebServerApplicationContext}中没有定义所需类型的{@link WebServerFactory} bean时抛出的异常。
 * @author Guirong Hu
 * @author Andy Wilkinson
 * @since 2.7.0
 */
public class MissingWebServerFactoryBeanException extends NoSuchBeanDefinitionException {

	private final WebApplicationType webApplicationType;

	/**
	 * 创建一个新的{@code MissingWebServerFactoryBeanException}。
	 * @param webServerApplicationContextClass 需要WebServerFactory的WebServerApplicationContext的类
	 * @param webServerFactoryClass 缺少的WebServerFactory的类
	 * @param webApplicationType Web应用程序的类型
	 */
	public MissingWebServerFactoryBeanException(
			Class<? extends WebServerApplicationContext> webServerApplicationContextClass,
			Class<? extends WebServerFactory> webServerFactoryClass, WebApplicationType webApplicationType) {
		super(webServerFactoryClass, String.format("Unable to start %s due to missing %s bean",
				webServerApplicationContextClass.getSimpleName(), webServerFactoryClass.getSimpleName()));
		this.webApplicationType = webApplicationType;
	}

	/**
	 * 返回缺少{@link WebServerFactory} bean的Web应用程序类型。
	 * @return Web应用程序的类型
	 */
	public WebApplicationType getWebApplicationType() {
		return this.webApplicationType;
	}

}
